<html>
<head>
</head>
<body>
<script type="text/javascript" src="jquery-142.js"></script>
<link rel="stylesheet" href="sosocial_gdoc.css" type="text/css" media="screen" />
<script>
String.prototype.endWith = function(it) { return (this.lastIndexOf(it) + it.length) == this.length; };

function ajax(args, callback) {
  args.success = function(data, status, xhr) {
    var result = { data:data, status:status };
    if ($.isFunction(callback)) callback(result);
  }
  args.error = function(xhr, status, error) {
    var result = { error:error, status:status };
    if ($.isFunction(callback)) callback(result);
  }

  $.ajax(args);
}

function init(callback) {
  var result = { tpls : {} };
  $('textarea').each(function() {
    if (this.id.endWith('-tpl')) {
      result.tpls[this.id] = $(this).val();
    }
  });

  callback(result);
}

function onRequest(args, sender, callback) {
  if (args.action == 'ajax') ajax(args, callback);
  if (args.action == 'init') init(callback);
}

// Wire up the listener.
chrome.extension.onRequest.addListener(onRequest);
</script>

<textarea id="test-tpl">
</textarea>

</body>
</html>